package zonghe.exer05;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] res = new int[101][101];
        for (int i = 1; i <= 100; i++) {
            for (int j = 1; j <= 100; j++) {
                res[i][j] = _dfs(i, j);
            }
        }
        System.out.println(Arrays.toString(res));
    }

    private static int _dfs(int m, int n) {
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(1);
        int count = 1;
        while (!queue.isEmpty()) {
            int size = queue.size();
            int oneCount = 0;
            while (size > 0) {
                int top = queue.poll();
                if (top == 1) {
                    oneCount++;
                    queue.offer(2);
                    queue.offer(n);
                } else if (top == n) {
                    queue.offer(n - 1);
                    queue.offer(1);
                } else {
                    queue.offer(top + 1);
                    queue.offer(top - 1);
                }
                size--;
            }
            if (count == m) {
                return oneCount;
            }
            count++;
        }
        return -1;
    }
}
